package com.wen.task.customTask;

import com.wen.moudle.Account;
import com.wen.moudle.Managers.BackpackManager;
import com.wen.task.AbstractTask;
import lombok.extern.slf4j.Slf4j;

import java.util.Scanner;


// 一键使用宝石buff药丸---完成
@Slf4j
public class UseGemPillsTask extends AbstractTask {
    BackpackManager backpackManager;

    public UseGemPillsTask(Account account) {
        super(account);
        backpackManager = getBackpackManager();
    }

    @Override
    public String getTitle() {
        return "一键使用buff药丸合成宝石";
    }

    @Override
    public void run() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("是否一键使用所有药丸和宝石？[y/n]");
        if (scanner.nextLine().charAt(0) == 'y'){
            useGoods("经验丸");
            useGoods("敏捷丸");
            useGoods("大力丸");
            useGoods("速度丸");
            combineGem("一级宝石");
            combineGem("二级宝石");
            combineGem("三级宝石");
            combineGem("四级宝石");
            combineGem("五级宝石");
            combineGem("六级宝石");
        }
    }

    public void useGoods(String name){
        int id = backpackManager.getGoodId(name);
        int count = 0;
        int group = 0;
        while (backpackManager.useGood(id).isSuccess()) {
            count++;
            group++;
            if (group == 20){
                group = 0;
                log.info("使用了 {} 个 {}", count,name);
            }
        }
        log.info("使用了 {} 个 {}", count,name);
    }

    public void combineGem(String name){
        int id = backpackManager.getGoodId(name);
        int count = 0;
        int group = 0;
        while (backpackManager.combineGood(id).isSuccess()){
            count++;
            group++;
            if (group == 20){
                group = 0;
                log.info("使用了 {} 个 {}", count,name);
            }
        };
        log.info("使用了 {} 个 {}", count,name);
    }
}
